Iâm trying to query a list of users by team_ids using PowerShellâs Invoke-RestMethod. Unfortunately, the body, which declares team_ids = is returning an error:
{âerrorâ:{âmessageâ:âInvalid Input Providedâ,âcodeâ:2001,âerrorsâ:[âTeam ids must be a Array.â]}}
Hereâs the code:
<#------------USERS------------#>
$apiRoot = âhttps://api.pagerduty.com/usersâ
$headers = New-Object âSystem.Collections.Generic.Dictionary[[String],[String]]â
$headers.Add(âAcceptâ, âapplication/vnd.pagerduty+json;version=2â)
$headers.Add(âAuthorizationâ, âToken token=InsertTokenHereâ)
$body = @{
âlimitâ = â100â
âteam_idsâ= @(âPZYAW28â)
}
$contentType = âapplication/jsonâ
$users = Invoke-RestMethod -Uri $apiRoot -ContentType âapplication/jsonâ -Method Get -Header $headers -Body $body
$userArray = @()
Foreach ($user in $users.users){
$psObject = New-Object -TypeName PSObject
$psObject | Add-Member -MemberType NoteProperty -Name userName -Value $user.name
$psObject | Add-Member -MemberType NoteProperty -Name userEmail -Value $user.email
$psObject | Add-Member -MemberType NoteProperty -Name userTimeZone -Value $user.time_zone
$psObject | Add-Member -MemberType NoteProperty -Name userRole -Value $user.role
$psObject | Add-Member -MemberType NoteProperty -Name userID -Value $user.id
$userArray += $psObject
}
$userArray | Sort userName | Format-Table
When I run this without the team_ids specified in the body, I get results. I also tried:
$body = @{
âlimitâ = â100â
âteam_idsâ= @(âPZYAW28â)
} | ConvertTo-Json
Which stores the following in the $body variable:
{
âlimitâ: â100â,
âteam_idsâ: [
âPZYAW28â
]
}
But I get this error from PowerShell:
Invoke-RestMethod : Cannot send a content-body with this verb-type.
I appreciate any help!